package implementor;


import daoInterface.CustomerDao;
import dbhandeling.Crude;

import dto.Customer;


public class CustomerImp extends Crude implements CustomerDao
{
	String className = new Customer().getClass().getName();
	@Override
	public void add(Customer cat) throws Exception {
		super.insert(cat);
	}

	@Override
	public void update(Customer cat) throws Exception {
		super.update(className, "customerName", cat.getCustomerName(), "customerId",cat.getAutocustomerId()+"");
		super.update(className, "customerPhone", cat.getCustomerPhone()+"", "customerId",cat.getAutocustomerId()+"");
		
		
	}

	@Override
	public void delete(Customer cat) {
		// TODO Auto-generated method stub
		super.delete(className, "customerId",cat.getAutocustomerId()+"");
	}

	@Override
	public Customer[] retrieveArray(String conditionField,
			String conditionValue) throws Exception {
		Object[] cat= super.retreiveArrayOnCondition(className, conditionField, conditionValue);
		Customer[]s=new Customer[cat.length];
		
		for(int i=0;i<s.length;i++)
			s[i]=(Customer) cat[i];
		return s;
	}

	@Override
	public Customer[] retrieveAll() throws Exception {
		Object[] cat= super.retreiveAll(className);
		Customer[]s=new Customer[cat.length];
		
		for(int i=0;i<s.length;i++)
			s[i]=(Customer) cat[i];
		return s;}

	@Override
	public Customer retrieve(String conditionField,
			String conditionValue) throws Exception {
		Customer cat=(Customer) super.retreive(className, conditionField, conditionValue);
		return cat;
	}

	public int getAutoGenratedKey()
	{
		 int key=super.getAutoGenratedKey(className,"autocustomerId") ;
		 return key;
	}
	
}
